package com.jerry.exception;

import com.jerry.interfaces.IResponse;

import java.text.MessageFormat;

public class BaseException extends RuntimeException implements IResponse {
    private final Integer code;
    private final String msg;
    private final IResponse response;

    public BaseException(IResponse response, Object[] args, String msg) {
        super(msg == null ? response.getMsg() : msg);
        this.response = response;
        this.code = response.getCode();
        this.msg = MessageFormat.format(response.getMsg(), args);
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public IResponse getResponse() {
        return response;
    }

}
